﻿using Comm.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Comm.Web.View
{
    public partial class OrderManager :Basepage
    {
        BLL.OrdersService bllOrders = new BLL.OrdersService();
        BLL.UsersService bllUsers = new BLL.UsersService();
        protected string strMsg = string.Empty;
        protected string strHtml = string.Empty;
        public override void SonLoad()
        {
            IList<Users> list1 = bllUsers.GetUserList();
            IList<Orders> list2 =bllOrders.GetOrderList();
            StringBuilder sb = new StringBuilder(2000);
            foreach (Model.Users user in list1) 
            {
                int userOrder = 0;
                int count = 0;
                foreach (Model.Orders orders in list2) 
                {
                  if(user.uId==orders.UserId)
                  {
                      userOrder++;
                      if (count == 0) 
                      {
                          sb.Append("<tr><td colspan=\"2\"><span style=\"margin-left:30px;\">用户【" + user.uLoginName+ "】的订单</span></td></tr>");
                          sb.Append("<tr><td colspan=\"5\"><table id=\"tbList\"><tr><th>订单号</th><th>订单时间</th><th>订单总价(元)</th><th>收件人地址</th><th>订单状态</th>");
                          count++;
                      }
                      if (int.Parse(orders.state.ToString()) == 0)
                      {
                          strMsg = "未处理";
                      }
                      else if (int.Parse(orders.state.ToString()) == 1)
                      {
                          strMsg = "已处理";
                      }
                      sb.Append("<tr class=\"align_Center\">");
                      sb.Append("<td style=\"width:20%; \"><span>"+orders.OrderId+"</span></td>");
                      sb.Append(" <td class=align_Left><span>"+orders.OrderDate+"</span></td>");
                      sb.Append("<td style=\"width:10%; \"><span class=\"price\">￥" + orders.TotalPrice + "</span></td>");
                      sb.Append("<td style=\"width:40%; \"><span class=\"address\">" + orders.PostAddress + "</span></td>");
                      sb.Append("<td style=\"width:8%; \"><span class=\"orderState\" style=\"cursor: pointer;\" orderId=\"" + orders.OrderId + "\">" + strMsg + "</span></td>");
                      sb.Append("</tr>");
                  }
                }
                if (userOrder != 0) 
                {
                    sb.Append("</tr></table></td></tr>"); 
                }
            }
            strHtml = sb.ToString();
        }
    }
}